package com.dunqi.gpm.cangxi.home.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.dunqi.gpm.cangxi.R;
import com.dunqi.gpm.cangxi.common.base.BaseAct;
import com.dunqi.gpm.cangxi.common.view.ComTitleBar;
import com.dunqi.gpm.cangxi.home.constance.Constance;
import com.dunqi.gpm.cangxi.home.fragment.WorkInstructionsFrgament;
import com.dunqi.gpm.cangxi.mine.util.UserUtil;

import butterknife.BindView;

// gongzuo 批示
public class WorkInstructionsActivity extends BaseAct {


    @BindView(R.id.title_bar)
    ComTitleBar titleBar;
    private WorkInstructionsFrgament frgament;

    @Override
    protected void refreshData(Bundle savedInstanceState) {

    }

    @Override
    protected void initUiAndListener() {

        final long mainObjectId = getIntent().getLongExtra(Constance.MAIN_OBJECT_ID, 0);
        final long instructionType = getIntent().getLongExtra(Constance.INSTRUCTION_TYPE, 0);

        int levelType = UserUtil.getLevelType();
        titleBar.setTitle("批示及留言");
        if (UserUtil.userIsLeader()) {
            titleBar.setRightText("新批示");
        } else {
            titleBar.setRightText("新留言");
        }

        frgament = WorkInstructionsFrgament.newInstance(mainObjectId, instructionType, false);
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container, frgament)
                .commit();

        titleBar.setOnClickListenerOfRight(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int msgType = UserUtil.getLevelType();
                if (msgType == 3) {
                    msgType = 2;
                }
                InstructionsActivity.start(getActivity(), mainObjectId,instructionType, msgType, 0l);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        frgament.onActivityResult(requestCode, resultCode, data);
    }

    public static void start(Context context, Long mainObjectId, Long instruction_type) {
        Intent intent = new Intent(context, WorkInstructionsActivity.class);
        intent.putExtra(Constance.MAIN_OBJECT_ID, mainObjectId);
        intent.putExtra(Constance.INSTRUCTION_TYPE, instruction_type);
        context.startActivity(intent);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_work_instructions;
    }


}
